package com.j.lemon.learn.basic.practice;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.util.*;

//@Controller
public class MyMain {

    public static void main(String[] args) {
        //        String data="{\"name\":\"hehehe\",\"nickname\":\"hahaha\"}";
//        JSONObject jsonObject= JSONObject.fromString(data);
//        Student s1;
//        s1= (Student) JSONObject.toBean(jsonObject,Student.class);
//        System.out.println(s1.getAge());
//        int a = 00022;
//        System.out.println(a);
        double money = 3.0;
        double a = money-2.9;
        System.out.println(a);
        double c = 0.1;
        System.out.println(c);
//        int num=100;
//        for(int i=0;i<100;i++){
//
//        }
        String abc="123你";
        String cba="123/11r/rr";
        System.out.println(cba.indexOf("/",cba.indexOf("/")+1));
        System.out.println(abc==cba);
        System.out.println(abc.length());
        char aa='中';
        System.out.println(new Integer(12));
        Collection c1=new ArrayList();
        Collection c2=new HashSet();
        c1.add("a");
        c1.add("b");
        c2.addAll(c1);
        System.out.println(c1);
        System.out.println(c2);
        Collection c3 = new ArrayList();
        c3.add("b");
        System.out.println(c1.containsAll(c3));
        Object[] asd=c1.toArray();
        System.out.println(asd[1].toString());
//        char a = '\u4e2d';
        Map<Integer,Integer> map = new HashMap();
        map.put(1,2);
        map.put(1,3);
        for(Map.Entry<Integer,Integer> entry : map.entrySet()){
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }
        for(Object o : map.keySet()){

        }
//        System.out.println(a);


//        int a=6;
//        char b='a';
//        System.out.println(a+b);
//        System.out.println(b);
        int i = 9;
        int m =i++;
        System.out.println(m);
        System.out.println(i);
//        int a =15,b=12,c=3;
//        int t=a-b>0?a:b;
//        int n=t-c>0?t:c;
//        System.out.println(n);
//        String a = "4";
//        switch (a){
//            case "1":
//                System.out.println("1");
//                break;
//            case "2":
//                System.out.println("2");
//            default:
//                System.out.println("3");
//        }
//        System.out.println("start");
//        for (String s = "";s.equals("qqq");s+="q"){
//            System.out.println("s!=qqq");
//        }
//        System.out.println("end");
        //1+2+3...+10000
//        for(int i = 1,j=0;i<=10000;i++){
//            j+=i;
//            System.out.println(j);
//        }
//        System.out.println(shulie9jia99(3));
//        List<Integer> list = fanweineizhishu(5);
//        for (Integer i :list){
//            System.out.println(i);
//        }
//        int [] arr = new int[5];
//        int a = feibonaqie(7);
//        System.out.println(a);
//        int [] a  = new int[3];
//        a[0]=1;
//        a[1]=2;
//        a[2]=3;
//        int [] b = {14,1,3,12};
//        String [] c = {"haha","hehe","qwe","asd"};
//        String [] cc =new String[c.length+1];
//        System.arraycopy(c,0,cc,0,c.length);
//        System.out.println(Arrays.toString(cc));
//
//        c=Arrays.copyOf(c,c.length+2);
//        System.out.println(Arrays.toString(c));

//        String aa = "'ccc'\"";
//        System.out.println(aa);
//        Arrays.sort(c,new MyCompara());
//        System.out.println(Arrays.toString(c));
//        System.out.println(b.length);
//        System.out.println(Arrays.toString(a));
//        String [] arr = Arrays.toString(a).split(",");
//        System.out.println(arr[2]);
//        System.out.println(Arrays.equals(a,b));
//        Arrays.sort(b);
//        System.out.println(Arrays.toString(b));

//        int [] d = maopao(b);
//        System.out.println(Arrays.toString(d));
//        File file = new File("/Users/lijunjun/testsss");
//        deleteDir(file);
//        System.out.println(diguiFecnaqi(7));
//        System.out.println(diguijiecheng(5));

//        String ip ="192.168.1.1";
//        System.out.println(Arrays.toString(ip.split(",")));
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring/spring-context.xml");

//        int [] a = new int[5];
//        String [] b = new String[5];
//        boolean [] c = new boolean[5];
//        long [] d = new long[5];
//        System.out.println(Arrays.toString(d));
//
//        String asd = "1231";
////        System.out.println(asd.substring(0,8));
//        System.out.println(Integer.valueOf(asd.substring(0,9)));
//        try {
////            Class c = Class.forName("com.jingantech.lemon.duotai");
////            Animal animal= (Animal) c.newInstance();
////            animal.run();
////            animal.eat();
//            String a = "我爱 peaking 天安门";
//            byte [] b=a.getBytes();
//            String c = new String (b,"utf-8");
//            System.out.println(c);
//            System.out.println();
//            System.out.println(Arrays.toString(a.getBytes()));
//            System.out.println(Arrays.toString(a.toCharArray()));
//            int dd = "a".toCharArray()[0];
//            System.out.println(dd);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        String str="good good study, day day up";
        str=str.replaceAll("\\s","");
        String [] strs=str.split("");
        Map<String,Integer> map1= new HashMap<>(16);
        for(String s : strs){
            if(map1.get(s)==null){
                map1.put(s,1);
            }else{
                map1.put(s,map1.get(s)+1);
            }
        }
        for(String key: map1.keySet()){
            System.out.println(key);
        }
        for(Map.Entry<String,Integer> entry:map1.entrySet()){
            System.out.println("key:"+entry.getKey()+",value:"+entry.getValue());
        }
        System.out.println(map1.toString());
        System.out.println(str);
    }





//    int c =wang(1,2,3);
//
//
//    public int wang(int a,int b,int c){
//        return 1;
//    }
//    public String wang(int a ,int b){
//        return "string wang";
//    }
    //二分法查找数组某个元素的位置
    public static Object erfenfa(Object [] objects,int value){
        int low = 1;
        int high=objects.length;
        int mid = -1;
        for(;;){
            mid=(low+high)/2;
            if((int)objects[mid]<value){
                low=mid+1;
            }else if ((int)objects[mid]>value){
                high=mid-1;
            }else{
                return mid+1;
            }
        }
    }
    //递归实现阶乘
    public static int diguijiecheng(int n){
        if(n==1){
            return 1;
        }else{
            return n*diguijiecheng(n-1);
        }
    }
    //递归实现打印第n个斐波那契额数
    public static int diguiFecnaqi(int n){
        if(n<3){
            return 1;
        }else{
            return diguiFecnaqi(n-1)+diguiFecnaqi(n-2);
        }
    }
    //递归删除目录
    public static void deleteDir(File file){
        if(file.isDirectory()){
            File [] files=file.listFiles();
            for (File f:files){
                deleteDir(f);
            }
        }
        file.delete();
    }
    //冒泡排序
    public static int [] maopao(int [] arr){
        for(int i = 0 ; i<arr.length-1;i++){
            for(int j =0;j<arr.length-1-i;j++){
                if (arr[j]>arr[j+1]){
                    int t = arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=t;
                }
            }
        }
        return arr;
    }
    //打印n的阶乘
    public static int jiecheng(int num){
        int j =1;
        for(int i = 1;i<=num;i++){
            j*=i;
        }
        return j;
    }

    public static int shulieqiuhe(int num){
        int tem;
        int j =1;
        for(int i =0;i<num;i++){
            j= (int) (Math.pow(10,i)*9);
        }
        return j;
    }

    //计算9+99+999+9999 到第n个
    public static int shulie9jia99(int n){
        int result =0;
        int j = 0;
        for(int i =0;i<n;i++){
            j+=Math.pow(10,i)*9;
            result+=j;
        }
        return result;
    }

    //列出范围内质数
    public static List<Integer> fanweineizhishu(int range){
        List<Integer> list = new ArrayList<>();
        for (int i=1;i<=range;i++){
            if(i<=3){
                list.add(i);
            }else{
                boolean flag = false;
                for(int j =2;j<i;j++){
                    if(i%j==0){
                        flag=true;
                    }
                }
                if(!flag){
                    list.add(i);
                }
            }
        }
        return list;
    }
    //打印斐波那契数列的第n个
    public static int feibonaqie(int n){
        int a =1;
        int b =1;
        if(n<=2){
            return 1;
        }else if (n==3){
            return 2;
        }else{
            int c =0;
            for(int i =0;i<n-3;i++){
                c=b;
                b=a+b;
                a=c;
            }
            return a+b;
        }
    }
}
